﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using BCEntity.OA.Workflow.WorkflowActivityStep;
using BCCommon;

namespace BCData.OA.Workflow.WorkflowActivityStep
{
    public class WorkflowActivityStepData : IWorkflowActivityStepData
    {
        private const string QUERY = @"SELECT WorkflowActivityStepId,WorkflowActivityId,TaskStep,ParentStep,StepName,AssignBased,AssignMode,TaskMethodTitle,
                                              TaskServiceName,IsBaseHandleMode,TaskMethodName,TaskMethodParameters,StepType,GotoStep,CompanyId,DepartmentId,
                                              WorkingGroupId,Role,AdminId,Position,RoleType,CanReject,RejectGotoStep,CanClose,CreateTime,UpdateTime
                                       FROM OA_WorkflowActivityStep";

        private readonly IDatabaseContext databaseContext;

        public WorkflowActivityStepData(IDatabaseContext databaseContext)
        {
            this.databaseContext = databaseContext;
        }

        public async Task<IEnumerable<WorkflowActivityStepEntity>> Get(long workflowActivityId)
        {
            string sql = string.Format("{0} WHERE WorkflowActivityId=?WorkflowActivityId", QUERY);
            DynamicParameters parameters = new DynamicParameters();
            parameters.Add("?WorkflowActivityId", workflowActivityId, DbType.Int64, size: 20);
            return await this.databaseContext.Slave.QueryAsync<WorkflowActivityStepEntity>(sql, parameters);
        }
    }
}
